package com.overlord.im.server.mapstruct;

import com.overlord.im.commons.message.OverlordImMessage;
import com.overlord.im.server.message.entity.ServerMessageEntity;
import com.overlord.im.server.message.entity.MessageAckEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

/**
 * @author wuwei
 * @className MessageMapper
 * @description
 * @date 2020-05-31 01:22
 **/
@Mapper(componentModel = "spring")
public interface MessageMapper {

    @Mappings({@Mapping(source = "msgType", target = "msgType"),
            @Mapping(source = "to", target = "msgTo"), @Mapping(source = "from", target = "msgFrom")})
    ServerMessageEntity toServerMessage(OverlordImMessage overlordImMessage);

    @Mappings({@Mapping(source = "msgType", target = "msgType"),
            @Mapping(source = "msgFrom", target = "from"), @Mapping(source = "msgTo", target = "to")})
    OverlordImMessage toBaseMessage(ServerMessageEntity serverMessageEntity);

    @Mappings({@Mapping(target = "id", ignore = true), @Mapping(target = "createTime", ignore = true), @Mapping(target =
            "sendTime", ignore = true)})
    MessageAckEntity toAck(ServerMessageEntity serverMessageEntity);
}
